package com.yunze.common.utils.yunze;

import com.github.stupdit1t.excel.common.PoiWorkbookType;
import com.github.stupdit1t.excel.core.ExcelHelper;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class exportExclCZC {
    /**
     * 导出 账单方法
     */
    public static void exportBill(List<Map<String,Object>> outList,String newName){
        ArrayList<Map<String, Object>> maps = new ArrayList<>();
        for (int i = 0; i < outList.size(); i++) {
            List<Map<String,Object>> plist1 = (List<Map<String,Object>>)outList.get(i).get("plist");
            if (plist1.size()!=0){
                for (int j = 0; j < plist1.size(); j++) {
                    Map<String, Object> map9 = plist1.get(j);
                    maps.add(map9);
                }
            }

        }
        try{
            File file2 = new File("");
            String filePath = file2.getCanonicalPath();
            File fileDir = new File(filePath+"/mnt/yunze/download/csv/"+newName);
            String parent = fileDir.getParent();
            File file = new File(parent);
            if (file.exists()){
                //是文件夹
            }else {
                //不是文件夹
                file.mkdirs();//创建
            }
            //文件最终路径

            ExcelHelper.opsExport(PoiWorkbookType.XLSX)
                    .parallelSheet()
                    .opsSheet(maps)
                    .sheetName("资费计划")
                    .opsHeader().simple()
                    .texts("企业ID", "资费计划","本月激活数量","停机数量","未激活数量","总数","本月用量","本月剩余用量").done()
                    .opsColumn()
                    .fields("dept_id","packet_id","activecount","haltcount","notactivecount","count","used","remaining").done()
                    .done()
                    .opsSheet(outList)
                    .sheetName("企业")
                    .opsHeader().simple().texts("企业id", "企业名称","本月激活数量","未激活数量","卡总数","停机数量","用量","剩余用量","时间").done()
                    .opsColumn().fields("dept_id", "dept_name","active_count","not_active_count","count","halt_count","used","remaining","month").done()
                    .done()

                    .export(fileDir.getPath());

        }catch(Exception e){

        }



    }
    public static void main(String[] args) {
        try{
            File file2 = new File("");
            String filePath = file2.getCanonicalPath();
            System.out.println(filePath);
        }catch(Exception e){}


    }
}


